package com.ujiuye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ujiuye.config.PageResult;
import com.ujiuye.config.QueryPageBean;
import com.ujiuye.mapper.UserMapper;
import com.ujiuye.pojo.User;
import com.ujiuye.service.IUserService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户 ----系统管理员 服务实现类
 * </p>
 *
 * @author zs
 * @since 2021-07-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public PageResult userList(QueryPageBean queryPageBean) {
        Page<User> Page = new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        String queryString = queryPageBean.getQueryString();
        QueryWrapper<User> queryWrapper = new QueryWrapper();
        if (queryString!=null && queryString.length()>0){
            queryWrapper.eq("username",queryString).or().eq("telephone",queryString);
        }
        Page<User> userPage = userMapper.selectPage(Page, queryWrapper);
         PageResult pageResult = new PageResult(userPage.getTotal(),userPage.getRecords());

        return pageResult;
    }

    @Override
    public User getUserByName(String username) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("username",username);
        return userMapper.selectOne(userQueryWrapper);
    }
}
